package util

import (
	"math/rand"
	"os"
	"strings"
	"time"
)

func IsPathExist(path string) bool {
	_, err := os.Stat(path)
	return err == nil || os.IsExist(err)
}

// https://i.loli.net/2020/07/28/q74soVAQbl5NyK6.jpg，返回 q74soVAQbl5NyK6.jpg
func GetFileSuffix(fileName string) string {
	index := strings.LastIndex(fileName, "/")
	fileName = fileName[index+1:]
	return fileName
}

func GetRandom() []byte {
	str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	destr := []byte(str)
	result := []byte{}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < 12; i++ {
		result = append(result, destr[r.Intn(len(destr))])
	}
	return result
}
